package com.situ.mall.product.controller;


import com.situ.mall.common.util.Result;
import com.situ.mall.pojo.entity.product.Category;
import com.situ.mall.product.pojo.vo.CategoryVO;
import com.situ.mall.product.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品分类 前端控制器
 * </p>
 *
 * @author Z
 * @since 2024-10-09
 */
@RestController
@RequestMapping("product/category")
public class CategoryController {
    @Autowired
    ICategoryService categoryService;
    @RequestMapping("/selectCategoryTree")
    public Result<List<CategoryVO>> selectCategoryTree() {
        List<CategoryVO> categoryVOList = categoryService.selectCategoryTree();
        return Result.ok(categoryVOList);
    }
    @RequestMapping("/selectByParentId/{id}")
    public Result<List<CategoryVO>> selectByParentId(@PathVariable Long id) {
        System.out.println(id);
        List<CategoryVO> categoryVOList = categoryService.selectByParentId(id);
        return Result.ok(categoryVOList);
    }
    @RequestMapping("/selectAllCategory1")
    public Result<List<Category>> selectAllCategory1() {
        List<Category> categoryList = categoryService.selectAllCategory1();
        return Result.ok(categoryList);
    }
    @PutMapping("/update")
    public Result update(@RequestBody Category category) {
        categoryService.update(category);
        return Result.ok("更新成功");
    }

    @DeleteMapping("/deleteById")
    public Result deleteById(@PathVariable Long id) {
        categoryService.deleteById(id);
        return Result.ok();
    }

}

